#!/bin/env bash

case $BLOCK_BUTTON in
	1) setsid "$TERMINAL" -e alsamixer & ;;
	3) pgrep -x dunst >/dev/null && notify-send "<b>📢 Volume module:</b>
- Shows volume 🔊, 🔇 if muted.
- Middle click to mute.
- Scroll to change."
esac

[ "$(amixer get Speaker | egrep 'Playback.*?\[o' | egrep -o -m 1 '\[o.+\]')" = "[off]" ] && printf "🔇\\n" && exit

vol=$(awk -F"[][]" '/dB/ { print $2 }' <(amixer sget PCM) | egrep -m 1 % | tr -d '%')

if [ "$vol" -gt "70" ]; then
	icon="🔊"
elif [ "$vol" -lt "30" ]; then
	icon="🔈"
else
	icon="🔉"
fi

printf "%s %d%%\\n" "$icon" "$vol"
